﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Strings - concatenation</title>
</head>
<body>

    <a href="http://jsperf.com/js-str-concat/2">jsperf test on concatenation</a>
    <script>
        function buildStringBuilder() {
            return {
                strs: [],
                len: 0,
                append: function (str) {
                    this.strs[this.len++] = str;
                    return this;
                },
                toString: function () {
                    return this.strs.join("");
                }
            };
        }

        var count = 30000;
        var s = "Test string!";

        var str = "";
        for (var i = 0; i < count; i++) {
            str += s + s + s + s + s;
        }

        var stringBuilder = buildStringBuilder();

        for (var i = 0; i < count; i++) {
            stringBuilder.append(s).append(s).append(s).append(s).append(s);
        }

        stringBuilder.toString();

    </script>
</body>
</html>
